package com.winit.schedule.core.protocol;

public class Protocol {

    public enum RequestCode {
        // 心跳
        HEART_BEAT(10),
        // 完成任务
        COMPLETE_TASK(11),
        // 删除任务
        STOP_TASK(13),
        // 删除作业
        STOP_JOB(14),
        // quartz作业
        QUARTZ_REQ(15);

        private int code;

        RequestCode(int code){
            this.code = code;
        }

        public static RequestCode valueOf(int code) {
            for (RequestCode requestCode : RequestCode.values()) {
                if (requestCode.code == code) {
                    return requestCode;
                }
            }
            throw new IllegalArgumentException("can't find the request code !");
        }

        public int code() {
            return this.code;
        }
    }

    public enum ResponseCode {
        // 心跳成功
        SUCCESS(50),

        UNKNOW(100);

        private int code;

        ResponseCode(int code){
            this.code = code;
        }

        public static ResponseCode valueOf(int code) {
            for (ResponseCode responseCode : ResponseCode.values()) {
                if (responseCode.code == code) {
                    return responseCode;
                }
            }
            throw new IllegalArgumentException("can't find the response code !");
        }

        public int code() {
            return this.code;
        }

    }
}
